package ubi.quando.UI;

import java.util.Date;

import ubi.quando.App.EventBase;
import ubi.quando.App.EventPickUp;
import ubi.quando.App.EventType;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class ArrangePickMeUpActivity extends ArrangeEventBaseActivity {
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		mLoutParticipants.setVisibility(View.GONE);
		mAddParticipantsBtn.setVisibility(View.GONE);
	}

	@Override
	protected void InitializeEvent() {
		mEvent = new EventPickUp(null, new Date(), mApp.getId(), null, null);
	}

	protected void onResume() {
		super.onResume();
		mApp.setCurrentActivity(this);

		Bundle b = getIntent().getExtras();
		if (b != null) {
			mEvent = (EventPickUp) b.getSerializable(EventBase.SerializeName);
		}

		updateDisplay();
	}

	@Override
	protected void updateDisplay() {
		super.updateDisplay();

		if (((EventPickUp) mEvent).GetPickUpLocation() != null) {
			mLocationDisplay.setText(((EventPickUp) mEvent).getmPULName());
		} else {
			mLocationDisplay.setText("No pick up location");
		}
	}

	@Override
	protected void SetEventType(Bundle b) {
		if (b != null) {
			EventType type = EventType.PICK_ME_UP;
			saveEventTypeToBundle(type, b);
		}
	}

	protected void ConfirmEvent(View v) {
		if (!IsEventValid()) {
			return;
		}
		EventPickUp event = (EventPickUp) mEvent;
		if (event.GetPickUpLocation() == null) {
			Toast.makeText(getApplicationContext(),
					"You must define pick up location", Toast.LENGTH_LONG)
					.show();
			return;
		}

		if (mApp.getServerComm().createPickupEvent(null, event.GetName(), event.GetDestination(),
				 event.GetDate(), event.GetPickUpLocation(), null, mApp.getId()) != null) {
			// shouldn't add the event. it will be added as an invitation
			// from the picker volunteer.
		}
		super.ConfirmEvent(v);
	}

	@Override
	protected void AddParticipants(View v) {
		// No adding participants in this mode,
		// should never be here.
		return;
	}
}
